﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserLogin : System.Web.UI.Page
{
    string roleId = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtSFZH.Text.Trim() != string.Empty && txtName.Text.Trim() != string.Empty)
            {
                if (User_Control.User_Login(txtSFZH.Text.Trim(), txtName.Text.Trim()))
                {
                    //Session["sfzh"] = txtSFZH.Text.Trim();
                    Session["userName"] = txtName.Text.Trim();
                    Session["studIdcard"] = txtSFZH.Text.Trim();
                    DataTable dt = Exam.getUserInfoByLoginMsg(txtName.Text.Trim(), txtSFZH.Text.Trim());
                    if (dt.Rows.Count > 0)
                    {
                        DataRow dr = dt.Rows[0];
                        roleId = dr["RoleID"].ToString().Trim();
                        switch (roleId)
                        {
                            case "0":
                                Response.Redirect(BSUtility.mainUrl + "Default.aspx");
                                break;
                            case "99":
                                Response.Redirect(BSUtility.mainUrl + "admin/AdminHomePage.aspx");
                                break;
                            default:
                                break;

                        }
                    }

                    
                }
                else
                {
                    BSUtility.WindowAlert(this, "帐号或者密码错误!");
                }
            }
            else
            {
                BSUtility.WindowAlert(this, "内容为空");
            }
        }
        catch(TimeoutException ex)
        {
            BSUtility.WindowAlert(this, "登录异常");
        }
        
        
    }

}